#include "VertexFormats.fx"
#include "Lighting.fx"
#include "Fog.fx"

float4x4 world_view_proj : WORLD_VIEW_PROJECTION;
float4x4 world : WORLD;
float3 camera_pos : CAMERA_POS;

float3 light1_pos;
float3 light2_pos;
float3 light3_pos;
float3 light1_color = {0.9f, 0.2f, 0.2f}; 
float3 light2_color = {0.2f, 0.9f, 0.2f};
float3 light3_color = {0.2f, 0.2f, 0.9f};
float3 light_attenuations;

float3 fog_color = float3(0, 0, 0);
float fog_start = 13.0;
float fog_length = 10.0;

struct VSOut 
{
    float4 pos : POSITION;
	float3 world_pos : TEXCOORD0;
	float3 color : COLOR;
};

VSOut VS_Tunnel(VertexPosNormal input)
{
    VSOut output;
	output.pos = mul(float4(input.pos, 1), world_view_proj);

	output.world_pos = mul(float4(input.pos, 1), world).xyz;
	float3 normal = normalize(mul(float4(input.normal, 0), world).xyz);

	output.color = pointLight(output.world_pos, normal, light1_pos,
		light1_color, float3(0, 0, light_attenuations.x), 0.12);
	output.color += pointLight(output.world_pos, normal, light2_pos,
		light2_color, float3(0, 0, light_attenuations.y), 0.12);
	output.color += pointLight(output.world_pos, normal, light3_pos,
		light3_color, float3(0, 0, light_attenuations.z), 0.12);

    return output;
}

float4 PS_Tunnel(VSOut input) : COLOR
{
	return float4(quadraticFog(input.world_pos, camera_pos, input.color, 
		fog_color, fog_start, fog_start + fog_length), 1);
}

technique t0
{
    pass p0
    {
        VertexShader = compile vs_2_0 VS_Tunnel();
        PixelShader = compile ps_2_0 PS_Tunnel();
    }
}
